const Router = require('koa-router')
const sha1 = require('sha1')
const opts = require('../config')
//sha1
module.exports = app => {
    const router = new Router()
    router.get('/', (ctx, next) => {
        const token = opts.wechat.token
        const {
            signature,
            nonce,
            timestamp,
            echostr
        } = ctx.query
        const str = [token,timestamp,nonce].sort().join('')
        const sha = sha1(str)
        if(sha===signature)
        {
            ctx.body=echostr
        }else{
            ctx.body = 'failed'
        }
    })

    // router.post('/wechat-hear',(ctx,next){

    // })·
    app.use(router.routes())
    app.use(router.allowedMethods())
}
